/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            sellingCostManageInfo: {
                sellingCosts: [],
                total: 0,
                records: 1,
                moreCondition: false,
                bankId: '',
                conditions: {
                    beginTime: '',
                    endTime: '',
                    shopId: vc.getCurrentCommunity().shopId
                }
            }
        },
        _initMethod: function () {
            // $that.sellingCostManageInfo.conditions.beginTime = vc.getCurrentMonthFirst();
            // $that.sellingCostManageInfo.conditions.endTime = vc.getCurrentMonthLast();
            $that._listsellingCosts(DEFAULT_PAGE, DEFAULT_ROWS);
            vc.initDate('beginTime', function (_value) {
                $that.sellingCostManageInfo.conditions.beginTime = _value;
            });
            vc.initDate('endTime', function (_value) {
                $that.sellingCostManageInfo.conditions.endTime = _value;
            });
            //防止多次点击时间插件失去焦点
            document.getElementsByClassName(' form-control beginTime')[0].addEventListener('click', myfunc)

            function myfunc(e) {
                e.currentTarget.blur();
            }

            document.getElementsByClassName(" form-control endTime")[0].addEventListener('click', myfunc)

            function myfunc(e) {
                e.currentTarget.blur();
            }
        },
        _initEvent: function () {
            vc.on('sellingCostManage', 'listSellingCost', function (_param) {
                $that._listsellingCosts(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listsellingCosts(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listsellingCosts: function (_page, _rows) {
                $that.sellingCostManageInfo.conditions.page = _page;
                $that.sellingCostManageInfo.conditions.row = _rows;
                var param = {
                    params: $that.sellingCostManageInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/mallReport/sellingCost',
                    param,
                    function (json, res) {
                        var _sellingCostManageInfo = JSON.parse(json);
                        $that.sellingCostManageInfo.total = _sellingCostManageInfo.total;
                        $that.sellingCostManageInfo.records = _sellingCostManageInfo.records;
                        $that.sellingCostManageInfo.sellingCosts = _sellingCostManageInfo.data;
                        vc.emit('pagination', 'init', {
                            total: $that.sellingCostManageInfo.records,
                            dataCount: $that.sellingCostManageInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            //查询
            _querySellingCostMethod: function () {
                $that._listsellingCosts(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //重置
            _resetSellingCostMethod: function () {
                $that.sellingCostManageInfo.conditions.beginTime = "";
                $that.sellingCostManageInfo.conditions.endTime = "";
                $that._listsellingCosts(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _moreCondition: function () {
                if ($that.sellingCostManageInfo.moreCondition) {
                    $that.sellingCostManageInfo.moreCondition = false;
                } else {
                    $that.sellingCostManageInfo.moreCondition = true;
                }
            }
        }
    });
})(window.vc);
